package Application;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;

import Cluster.ClusteringProcess;
import Cluster.DrawPanel;
import Cluster.Trajectory;
import MyLoader.MyLoader;
import XmlLoader.FGObjProcess;
import XmlLoader.FGObjectTrajectoryStructure;

public class TrajShow {
	/**
	 * args[0] : file path of the trajectory index list
	 * args[1] : start index number of index content in args[0]
	 * args[2] : number of index content in args[0]
	 * args[3] : file path of directory storing list of trajectory xml file
	 * args[4] : maxDist
	 * args[5] : maxDist threshold (%) of a cluster
	 * args[6] : file path of cluster result
	 * @param 
	 */
	public static void main(String[] args) {
		//generate list trajectory index
		System.out.println("Generate trajectory index file");
		new ReadFileGenerateor().ACT001_genFile(args[0], Integer.parseInt(args[1]), Integer.parseInt(args[2]));
		
		//load trajectory xml data
		System.out.println("Load trajectory xml file");
		FGObjProcess fgObj = new FGObjProcess(args[3]);
		List<String> list_objIndex = fgObj.ACT004_getStringList(args[0]);
		List<FGObjectTrajectoryStructure> list = new MyLoader().ACT001_getListOfObj(args[3], list_objIndex);
		
		//do clustering
		System.out.println("Do clustering");
		//trajectory structure transformation
		ArrayList<Trajectory> listTraj = new ArrayList<Trajectory>();
		int index = 0;
		while(index < list.size()) {
			if(list.get(0).GET002_nNumberOfPoint() >= 2) {
			    listTraj.add(new Trajectory(list.get(0), 0, 0, list.get(0).GET002_nNumberOfPoint()));
			}
			list.remove(0);
		}
		System.out.println(listTraj.size());
		//do cluster
		ClusteringProcess cp = new ClusteringProcess();
		cp.ACT001_doCluster(ClusteringProcess.MATRIC_DTW, Integer.parseInt(args[4]), Integer.parseInt(args[5]), listTraj);
		//show result
		cp.ACT002_showResult();
		
		//show result of trajectory on frame
		JFrame.setDefaultLookAndFeelDecorated(true);
		JFrame frame = new JFrame("MyCanvasDemo_2");
		frame.getContentPane().add(new DrawPanel(args[3], args[0], args[6]));
		frame.getContentPane().setBackground(Color.WHITE);
		frame.setLocation(100,100);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
}
